package com.hospital.demo.controller.libokun;



import com.hospital.demo.model.libokun.Drug;
import com.hospital.demo.service.libokun.DrugService;
import com.hospital.demo.util.ResultUtils;
import com.hospital.demo.util.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "药品管理接口")
@CrossOrigin
@RestController
@RequestMapping("/DrugController")
public class DrugController {
    @Autowired
    DrugService drugService;


    @ApiOperation("查询全部药品")
    @GetMapping("/SelectDrugAll")
    public ResultVO SelectDrugAll(Integer page, Integer limit) {

        List<Drug> lists = drugService.SelectAllDrug();

        return ResultUtils.success(lists);
    }


    @ApiOperation("按ID查找药品")
    @GetMapping("/SelectById")
    public ResultVO SelectById(Integer drid) {
        List<Drug> lists = drugService.SelectById(drid);

        return ResultUtils.success(lists);
    }

//    @ApiOperation("按名称查找药品")
//    @PostMapping("/SelectByName")
//    public PageUtils SelectByName(String drname, Integer pageNum, Integer pageSize) {
//        PageUtils pageUtils = new PageUtils();
//        List<Drug> lists = drugService.SelectByName(drname);
//        pageUtils.setDataList(lists);
//        pageUtils.setCurrentPage(pageNum);
//        pageUtils.setPageSizes(pageSize);
//        return pageUtils.paging();
//    }

    @ApiOperation("删除药品")
    @PostMapping("/DelectDrug")
    public Map<String, Object> DelectDrug(Integer drid) {
        Map<String, Object> map = new HashMap<>();
        Integer Flag = drugService.DelectDrug(drid);
        if (Flag == 1) {
            map.put("msg", "删除操作成功");
        } else {
            map.put("msg", "删除操作失败");
        }
        return map;
    }
    @ApiOperation("添加药品")
    @PostMapping("/InsertDrug")
    public Map<String,Object> InsertDrug( Drug drug){
        Map<String,Object> map = new HashMap<>();
        List<Drug> Flag=drugService.InsertDrug(drug);

        if(Flag.equals("0")){
            map.put("msg","操作成功");
        }else{
            map.put("msg","操作失败");
        }
        return map ;
    }
    @ApiOperation("批量删除药品")
    @PostMapping("/DeleteManyDrug")
    public Map<String, Object> DeleteManyDrug( List<Integer> isStr) {
        Map<String, Object> map = new HashMap<>();
        Integer Flag = drugService.DeleteManyDrug(isStr);
        if (Flag >= 1) {
            map.put("msg", "操作成功");
        } else {
            map.put("msg", "操作失败");
        }
        return map;
    }
    @ApiOperation("更改药品信息")
    @PostMapping("/UpdateDrug")
    public Map<String, Object> UpdateDrug( Drug drug) {
        Map<String, Object> map = new HashMap<>();
        System.out.println(drug);
        List<Drug> Flag = drugService.UpdateDrug(drug);
        if (Flag.equals("0")) {
            map.put("msg", "操作成功");
        } else {
            map.put("msg", "操作失败");
        }
        return map;
    }




}
